import datetime

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver


class BlogUserTest:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    def UserEleTest(self):
        #头像框是否可以点击选择头像
        self.driver.find_element(By.CSS_SELECTOR,"#settings_avatar").send_keys("C:\Users\洋洋洋洋\Desktop\测试开发\BlogAutoTest\Avatar\img.png")
        BlogDriver.getScreeShot()

        #“修改头像”是否可以点击修改头像
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div.row.align-items-center > div:nth-child(2) > a").send_keys("C:\Users\洋洋洋洋\Desktop\测试开发\BlogAutoTest\Avatar\img_1.png")
        BlogDriver.getScreeShot()

        #昵称输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys("test")

        #邮箱地址输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").send_keys("2890556977")

        #电话号码输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").send_keys("17877354321")

        # 个人简介输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").send_keys("这个人很懒什么都没有输入")

        # 各“修改"按钮是否可以点击
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "")
        BlogDriver.getScreeShot()


        #原密码输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("123333")

        #新原密码输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("123000")

        #确认密码输入框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("123222")

        BlogDriver.getScreeShot()
        # “眼睛”显示填入信息按钮是否可以点击显示信息
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div:nth-child(14) > div > div > form > div:nth-child(1) > div > span > a > svg").click()
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div:nth-child(14) > div > div > form > div:nth-child(2) > div > span > a > svg").click()
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div:nth-child(14) > div > div > form > div:nth-child(3) > div > span > a > svg").click()
        BlogDriver.getScreeShot()

        #“提交修改”是否可以点击提交
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        BlogDriver.getScreeShot()
        self.driver.refresh()

    def UserNicknameTest(self):
        # 不输入字符进行修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        BlogDriver.getScreeShot()

        # 输入字符进行修改
        time = datetime.datetime.now().strftime("%H%M%S")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").send_keys("test"+time)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        BlogDriver.getScreeShot()

        # 清除已有字符进行修改
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        BlogDriver.getScreeShot()

    def UserEmailAddrTest(self):
        # 不输入邮箱进行修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        BlogDriver.getScreeShot()

        # 输入邮箱进行修改
        # 输入正确邮箱
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").send_keys("2890556976@qq.com")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()

        # 输入错误邮箱
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").send_keys("121212121a@qq.com")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").clear()

        # 清除已有邮箱进行修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        BlogDriver.getScreeShot()

    def UserTelephoneTest(self):
        #不输入电话号码进行修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        BlogDriver.getScreeShot()

        # 输入电话号码进行修改
        # 输入正确电话号码(不方便透露本人手机号码)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").send_keys("***********")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        BlogDriver.getScreeShot()

        # 输入错误电话号码
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").send_keys("11111111111")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        BlogDriver.getScreeShot()

        # 清除已有电话号码进行修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        BlogDriver.getScreeShot()

    def UserProfileTest(self):
        # 不填写后修改
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        BlogDriver.getScreeShot()

        # 填写后修改
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").send_keys("个人简介测试")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        BlogDriver.getScreeShot()


    def UserChgPassword(self):
        # 异常修改密码
        # 错填原密码
        self.driver.refresh()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("123000")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("123000")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        BlogDriver.getScreeShot()

        # 错填确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123222")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        BlogDriver.getScreeShot()

        # 原密码与新原密码相同
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        BlogDriver.getScreeShot()

        # 不填原密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123000")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123000")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        BlogDriver.getScreeShot()

        # 不填确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        BlogDriver.getScreeShot()

        # 正常修改密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        BlogDriver.getScreeShot()

        # 不要忘记改回来以便下次测试
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("2890556976")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123111")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()












